package cn.com.chengmandian.bike.service.impl;

import cn.com.chengmandian.bike.mapper.EbDepositConfigMapper;
import cn.com.chengmandian.bike.model.EbDepositConfig;
import cn.com.chengmandian.bike.service.IEbDepositConfigService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * <p>
 * 押金规则配置表 服务实现类
 * </p>
 *
 * @author AutoGenerator
 * @since 2021-12-15
 */
@Service
public class EbDepositConfigServiceImpl extends ServiceImpl<EbDepositConfigMapper, EbDepositConfig> implements IEbDepositConfigService {

    @Override
    public EbDepositConfig getConfig(Integer areaId) {
        EbDepositConfig config = this.getOne(new LambdaQueryWrapper<EbDepositConfig>()
                .eq(EbDepositConfig::getAreaId, areaId)
                .last("limit 1"));
        if (config == null) {
            config = new EbDepositConfig();
            config.setAreaId(areaId);
            config.setDepositMoney(new BigDecimal(100));
            config.setDepositFree(0);
            config.setIsForce(0);
            this.save(config);
        }
        return config;
    }
}
